<div id="container"></div>
<script>
  // function fn(p1, p2, callback) {
  //   if (p1>p2) {
  //     callback(null, p1 - p2)
  //   } else {
  //     callback('p1必须大于p2')
  //   }
  // }
  // fn(100, 20, function(error, success) {
  //   if(error) {
  //     console.warn(error)
  //   } else {
  //     console.log('结果：', success)
  //   }
  // })
  /*
const r = fn(10, 20)
if (r.error) {

} else {

}
*/

  function fn(p1, p2) {
    return new Promise((resovle, reject) => {
      if (p1 > p2) {
        resovle(p1 - p2)
      } else {
        reject('p1必须大于p2')
      }
    })
  }
  fn(100, 20)
    .then((v) => console.log(v))
    .catch((e) => console.warn(e))

  fn(10, 20)
    .then((v) => (document.getElementById('container').innerHTML = v))
    .catch((e) => {
      document.getElementById('container').innerText = e
      document.getElementById('container').style.color = 'red'
    })
</script>

<form method="post" action="./index.html">
  username: <input type="text" name="username" /> pass:
  <input type="password" name="password" />
  <button type="submit">ok</button>
</form>
<script type="module">
  import { ajax } from './ajax.js'
  ajax('./data.json')
    .then((json) => console.log(json))
    .catch((e) => console.log(e))
</script>

<script>
  function delay(ms) {
    return new Promise(function (resolve) {
      setTimeout(() => resolve(), ms)
    })
  }
</script>

<script>
// Promise.myResolve = function(v) {
//   return new Promise((resolve) => resolve(v))
// }

console.log(1)
Promise.resolve().then(() => console.log(3))
console.log(2)

[1,2,'b'].map(v => Promise.resolve(v))

</script>
